package com.mes.basicdata.domain;
/**
 * @author SnowBear
 * @Time 2017/3/15
 */
import javax.persistence.Entity;
import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;
import org.springframework.context.annotation.Lazy;

import com.mes.common.domain.BasicModel;

@Entity()
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "R_RESOURCE")
@Where(clause="RESOURCETYPE = 1")
@BatchSize(size=20)
@Lazy(value=true)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class WorkCenter extends BasicModel implements Serializable {
	private static final long serialVersionUID = 1L;

	// 资源编号
	@Id
	@GenericGenerator(name = "workCenterUid", strategy = "assigned")
	@Column(name = "RESUID",unique=true)
	private String workCenterUid;
	
	// 资源名称
	@Column(name = "RESNAME")
	private String workCenterName;
	
	//部门
	@Column(name = "DEPTID", length = 50)
	private String deptUid;
	
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "DEPTID", nullable = true,insertable=false,updatable=false)
	private Dept dept;
	
	// 父工作中心
	@Column(name = "RESTYPE")
	private String deviceClassUid;
	
	@ForeignKey(name="null")
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)//lazy = "proxy", insert = "false", update = "false", cascade = "none", fetch = "select"
	@JoinColumn(name = "RESTYPE",insertable=false,updatable=false)
	private DeviceClass deviceClass;
		
	// 默认日历
	@Column(name = "CAL_UID")
	private String defaultCalendarUid;
	
	@ForeignKey(name="null")
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "CAL_UID", insertable=false,updatable=false)
	private Calendar defaultCalendar;
	
	//工作中心类型
	@Column(name = "RESOURCETYPE")
	private String workCenterType = "1";
	
	// 默认安装时间
	@Column(name = "DEFAULT_SETUP_TIME", precision = 10, scale = 0)
	private Float defaultSetupTime;
	
		
	// 不需要派工标记
	@Column(name = "NONENEEDDISPATCH")
	private Integer dispatchGrade;
	
//	@ManyToOne(fetch=FetchType.LAZY)
//	@JoinColumnsOrFormulas(value={
//			@JoinColumnOrFormula(column=@JoinColumn(name="NONENEEDDISPATCH",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
//			@JoinColumnOrFormula(formula=@JoinFormula(value="'dispatchgrade'", referencedColumnName="TYPESNAME"))
//	})
//	@NotFound(action=NotFoundAction.IGNORE)
//	private TypesData dispatchGradeDesc;
	
	
	//关键级别
	@Column(name = "CRITICAL_LEVEL", precision = 2, scale =0)
	private Integer criticalLevel;
	
//	@ManyToOne(fetch=FetchType.LAZY)
//	@JoinColumnsOrFormulas(value={
//			@JoinColumnOrFormula(column=@JoinColumn(name="CRITICAL_LEVEL",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
//			@JoinColumnOrFormula(formula=@JoinFormula(value="'critical_level'", referencedColumnName="TYPESNAME"))
//	})
//	@NotFound(action=NotFoundAction.IGNORE)
//	private TypesData criticalLevelDesc;
	
	
	// 月计划工作时间
	@Column(name = "MONTHPLANWORK", precision = 10, scale =1)
	private Float monthPlanWorkTime;
	
	// 工种类型
	@Column(name = "OPTYPE", precision = 10, scale = 0)
	private String workType;
	
	//工作中心拥有设备的数量
	private Integer deviceCount;

	public String getWorkCenterUid() {
		return this.workCenterUid;
	}
	
	public void setWorkCenterUid(String workCenterUid) {
		this.workCenterUid = workCenterUid;
	}

	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getWorkCenterUid();
	}

	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setWorkCenterUid(uuid);
	}

	public String getWorkCenterName() {
		return this.workCenterName;
	}
	
	public void setWorkCenterName(String workCenterName) {
		this.workCenterName = workCenterName;
	}
	
	public String getDeptUid() {
		return this.deptUid;
	}
	
	public void setDeptUid(String deptUid) {
		this.deptUid = deptUid;
	}

	public String getDeviceClassUid() {
		return this.deviceClassUid;
	}
	
	public void setDeviceClassUid(String deviceClassUid) {
		this.deviceClassUid = deviceClassUid;
	}
	
	public DeviceClass getDeviceClass() {
		return this.deviceClass;
	}
	
	public void setDeviceClass(DeviceClass deviceClass) {
		this.deviceClass = deviceClass;
	}

	public String getDefaultCalendarUid() {
		return this.defaultCalendarUid;
	}
	
	public void setDefaultCalendarUid(String defaultCalendarUid) {
		this.defaultCalendarUid = defaultCalendarUid;
	}
	
	
	public Calendar getDefaultCalendar() {
		return this.defaultCalendar;
	}
	
	public void setDefaultCalendar(Calendar defaultCalendar) {
		this.defaultCalendar = defaultCalendar;
	}
	
//	@Column(name = "RESOURCETYPE")
	public String getWorkCenterType() {
		return this.workCenterType;
	}
	
	public void setWorkCenterType(String workCenterType) {
		this.workCenterType = workCenterType;
	}

	public Float getDefaultSetupTime() {
		return this.defaultSetupTime;
	}
	
	public void setDefaultSetupTime(Float defaultSetupTime) {
		this.defaultSetupTime = defaultSetupTime;
	}

	public Integer getDispatchGrade() {
		return this.dispatchGrade;
	}
	
//	public TypesData getDispatchGradeDesc() {
//		return dispatchGradeDesc;
//	}
//
//	public void setDispatchGradeDesc(TypesData dispatchGradeDesc) {
//		this.dispatchGradeDesc = dispatchGradeDesc;
//	}
	
	public void setDispatchGrade(Integer dispatchGrade) {
		this.dispatchGrade = dispatchGrade;
	}

	public Integer getCriticalLevel() {
		return this.criticalLevel;
	}
	
	public void setCriticalLevel(Integer criticalLevel) {
		this.criticalLevel = criticalLevel;
	}
	
//	public TypesData getCriticalLevelDesc() {
//		return criticalLevelDesc;
//	}
//
//	public void setCriticalLevelDesc(TypesData criticalLevelDesc) {
//		this.criticalLevelDesc = criticalLevelDesc;
//	}

	public Float getMonthPlanWorkTime() {
		return this.monthPlanWorkTime;
	}
	
	public void setMonthPlanWorkTime(Float monthPlanWorkTime) {
		this.monthPlanWorkTime = monthPlanWorkTime;
	}
	
	public String getWorkType() {
		return this.workType;
	}
	
	public void setWorkType(String workType) {
		this.workType = workType;
	}

	public Dept getDept() {
		return this.dept;
	}
	
	public void setDept(Dept dept) {
		this.dept = dept;
	}
	
	public Integer getDeviceCount() {
		return this.deviceCount;
	}
	
	public void setDeviceCount(Integer deviceCount) {
		this.deviceCount = deviceCount;
	}
	

}
